/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Sik
 */
public class Toolbox
{

    public static SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

    public static Date stringToDate(String sDate) throws ParseException
    {
        return formatter.parse(sDate);
    }
    

    public static Timestamp toDBDateFormat(String sDate) throws ParseException
    {
        return new Timestamp(stringToDate(sDate).getTime());
    }

    public static String dateToString(Date date)
    {
        return formatter.format(date);

    }
    
    public static String ExtractParameterFromQuery(String query, String expectedId)
    {
        String[] array = query.split("[=|?]");
        for(int i=0; i<array.length; i++)
        {
            if(array[i].equals(expectedId))
            {
                return array[i+1];
            }
        }
        return null;
    }
}
